<?php
/**
 * Created by jinqiang on 2024/8/21 13:32.
 * Copyright (c) 2024, Your Company. All rights reserved.
 */


namespace App\Http\Controllers\Op;


use App\Http\Controllers\Controller;
use App\Http\Services\Op\IpurchaseService;
use Illuminate\Http\Request;

class IpurchaseController extends Controller
{
    public function list(Request $request, IpurchaseService $ipurchaseService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $ipurchaseService->search($param);
        return result($res);
    }

    //我的内购列表
    public function myList(Request $request, IpurchaseService $ipurchaseService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $param['adduser'] = auth()->guard("api")->user()->name;
        $res = $ipurchaseService->search($param);
        return result($res);
    }

    //内购详情
    public function detail(Request $request, IpurchaseService $ipurchaseService)
    {
        $this->validate($request, [
            'allocation_number' => 'required'
        ]);
        $param = $request->all();
        $res = $ipurchaseService->detail($param['allocation_number']);
        return result($res);
    }

    //内购发起审批
    public function approval(Request $request, IpurchaseService $ipurchaseService)
    {
        $this->validate($request, [
            'detail' => 'required',
            'img' => 'required',
            'wp_user' => 'required',
            'wp_phone' => 'required',
            'wp_province' => 'required',
            'wp_city' => 'required',
            'wp_address' => 'required'
        ]);
        $param = $request->all();
        $res = $ipurchaseService->approval($param);
        return $res['code'] === 0 ? success("审批发起成功, 请前往飞书查看当前审批状态, 耐心等待...") : error($res['msg'], $res);
    }
}
